﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace L4View.Infrastructure
{
    public class MessageCollection : IMessageCollection
    {
        private LinkedList<IMessage> _messageList;

        public MessageCollection()
        {
            _messageList = new LinkedList<IMessage>();
        }

        public virtual ICollection<IMessage> GetMessages()
        {
            lock (_messageList)
            {
                return _messageList;
            }
        }

        public virtual void PutMessage(IMessage message)
        {
            lock (_messageList)
            {
                _messageList.AddLast(message);
            }
        }

        public virtual void Transfer(bool stop)
        {
            if (!stop)
                System.Threading.Monitor.Enter(_messageList);
            else
                System.Threading.Monitor.Exit(_messageList);
        }
    }
}
